package com.qf.first.controller;

import com.qf.first.entity.Finance;
import com.qf.first.exceptions.BaseException;
import com.qf.first.pojo.vo.FinanceVo;
import com.qf.first.pojo.vo.RespVo;
import com.qf.first.service.FinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@Api("商家财务模块")
@RestController
@RequestMapping("/finance")
public class FinanceController extends BaseController{
    @Autowired
    private FinanceService financeService;

    @ApiOperation("根据商户id获取订单")
    @GetMapping("/selectFinance")
    public RespVo selectFinance(HttpSession session, Finance finance){
        //获取商家id
        Long id = (Long) session.getAttribute("id");
        if (id == null){
            throw new BaseException(RespVo.CodeType.FAIL.getValue(),"请登录商户账号");
        }
        finance.setShopid(id);
        List<FinanceVo> financeVos = financeService.selectFinance(finance);
        System.out.println(financeVos);
        if (financeVos == null){
            return convertFail("再不加油您就吃土了");
        }
        return  convertSuccess(financeVos);


    }

}
